package test.src.awt_swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CourseDemo2 {
    JFrame jFrame = new JFrame();

    JPanel jPanel = new JPanel();

    JTextField jTextField = new JTextField(12);

    JTextArea jTextArea = new JTextArea(10, 10);

    JButton button = new JButton(new AbstractAction("确定") {
        @Override
        public void actionPerformed(ActionEvent e) {
            jTextArea.append(jTextField.getText());
            jTextArea.append("\n");
            JOptionPane.showMessageDialog(jFrame, (jTextField.getText()) + ":事件发生，我已知道");
        }
    });

    private void init() {
        jFrame.add(jPanel, BorderLayout.NORTH);
        jPanel.add(jTextField);
        jPanel.add(button);

        jFrame.add(jTextArea);

        jFrame.setPreferredSize(new Dimension(400, 240));
        jFrame.pack();
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {
        new CourseDemo2().init();
    }
}
